$(function() {
    $(window).bind("load resize", function() {
        topOffset = -50;
        width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width;
        height = (this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height;
        if(width < 428) {
            $('.row-fluid.home > div.col-md-3.col-sm-6').removeClass('col-xs-6');
        }else{
            $('.row-fluid.home > div.col-md-3.col-sm-6').addClass('col-xs-6');
        }
        if (width < 768) {
            $('div.navbar-collapse').addClass('collapse');
            topOffset = 0; // 2-row-menu
            $('.navbar-default.sidebar').removeAttr('style');
        } 
        else {
            var heightNavbar=$('.navbar').height();
            var heightSidebar=height-heightNavbar;
            $('.navbar-default.sidebar').attr('style','height:'+heightSidebar+'px;overflow:auto');
            $('div.navbar-collapse').removeClass('collapse');
        }
        height = height + topOffset;
        if (height < 1) height = 1;
        if (height > topOffset) {
            $("#page-wrapper").css("min-height", (height) + "px");
        }
    });
});
    var img_system="images/config.png";
    var img_content="images/pen.png";
    var img_plugin="images/box.png";
    var img_extension="images/extensions.png";
    var img_module="images/browser.png";
    var img_widget="images/widget.png";
$.ajax({
    type       : "GET",
    url        : menulink,
    dataType : "xml",
    /*beforeSend: function(xhr, settings) {
        $("#Li2").find("ul").remove();
    },*/          
    success  : function(xml){
      var ul_main=$("#side-menu"); 
      $(xml).find("menu").each(function(){
                $(this).children().each(function(){ 
                    var parent=$(this).attr("text");
                    if(parent=='System'){
                        img=$("<img>", {src:  img_system});
                     }else if(parent=='Content'){
                        img=$("<img>", {src:  img_content});
                     }else if(parent=='Plugins'){
                        img=$("<img>", {src:  img_plugin});
                     }else if(parent=='Extensions'){
                        img=$("<img>", {src:  img_extension});
                     }else if(parent=='Modules'){
                        img=$("<img>", {src:  img_module});
                     }else{
                        img=$("<img>", {src:  img_system});
                     }
                    var li_main=$("<li>");
                    var url_main=$("<a>",{href:"#",text:parent});
                    var arrow=$("<span>", {class:  "fa arrow"});
                    li_main.append(
                        url_main.append(arrow).prepend(img));
                    var subList = $("<ul>",{class:"nav nav-second-level"});
                    $(this).children().each(function(){ 
                        var sub=$(this).attr("text");
                        var url=$(this).attr("id").split('|');
                        if($(this).attr("text") && sub!="Logout"){
                            
                                subList.append(
                                /*'<li><a url="'+url[1]+'" id="menuActive">'+sub+'</a></li>'*/
                                '<li><a href="'+url[1]+'">'+sub+'</a></li>'
                                );
                        }
                        if(sub=="Logout"){
                            $('li#logout').html('<a href="'+url[1]+'">Sign Out</a>');
                        }
                        ul_main.append(li_main.append(subList))
                }); 
                }); 
                
            
        });
        //$('.tempat-table > script').remove();
        //$('.tempat-table > link').remove();
        $("#side-menu").metisMenu();
    }
});